#!/bin/bash

if [[ $# -ne 2 ]]; then
    echo "The format is as follows:"
    echo "bash pysam-0.8.2.sh buildpath installpath"
    echo ":param buildpath: 应用构建绝对路径"
    echo ":param installpath: 应用安装绝对路径"
    exit 1
fi

[[ ! "$1" =~ ^/.* || ! -d "$1" || "$1" = "/" ]] &&  echo "请输入正确的构建路径" && exit 1
[[ ! "$2" =~ ^/.* || ! -d "$2" || "$2" = "/" ]] &&  echo "请输入正确的安装路径" && exit 1

buildpath=$1
installpath=$2
[[ "$buildpath" =~ .*/$ ]] && buildpath=${buildpath%/*}
[[ "$installpath" =~ .*/$ ]] && installpath=${installpath%/*}
[[ "$buildpath" == "$installpath" ]] && echo "构建路径与安装路径需为不同路径" && exit 1
set -e
yum install -y wget tar environment-modules libatomic  

wget -t 10 -c -P $buildpath https://files.pythonhosted.org/packages/10/42/7f51e1ad0c283e1d6bf826d3a193fa0644e675c9c6d42263b69fefc3b527/pysam-0.8.2.tar.gz
tar xf $buildpath/pysam-0.8.2.tar.gz -C $buildpath && rm -rf $buildpath/pysam-0.8.2.tar.gz
cd $buildpath/pysam-0.8.2

$installpath/python-2.7.18/bin/python setup.py install --prefix=$installpath/python-2.7.18/

rm -rf $buildpath/pysam-0.8.2